Skip to content

test(parser): improve import_cache_test.go quality per testify-expert criteria#30218

Merged
pelikhan merged 3 commits intomainfrom
copilot/testify-expert-improve-test-quality-another-one
May 5, 2026
Merged

test(parser): improve import_cache_test.go quality per testify-expert criteria#30218
pelikhan merged 3 commits intomainfrom
copilot/testify-expert-improve-test-quality-another-one

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 4, 2026

TestImportCache subtests shared a single cache instance and silently swallowed Set errors, masking failures and creating inter-subtest dependencies. GetCacheDir lacked focused coverage, and TestSanitizePath was missing coverage for common filepath.Clean normalizations.

Changes

  • Test isolation — each TestImportCache subtest now creates its own NewImportCache(t.TempDir()), eliminating shared mutable state
  • Error checking — subtests that previously used cachedPath, _ := cache.Set(...) now use require.NoError, surfacing setup failures immediately
  • GetCacheDir coverage — added a nested-base-dir subtest inside TestImportCacheDirectory to cover the case where the base directory contains multiple path levels, without duplicating the existing assertion
  • TestSanitizePath edge cases — two additional cases documenting filepath.Clean behaviour:
    • "./file.md""file.md" (leading dot-slash stripped)
    • "a//b/file.md""a_b_file.md" (consecutive slashes collapsed)

Copilot AI changed the title [WIP] Improve test quality for import cache tests test(parser): improve import_cache_test.go quality per testify-expert criteria May 4, 2026
Copilot AI requested a review from gh-aw-bot May 4, 2026 20:16
@pelikhan pelikhan marked this pull request as ready for review May 4, 2026 20:39
Copilot AI review requested due to automatic review settings May 4, 2026 20:39
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Improves the import cache test suite by isolating TestImportCache subtests, surfacing setup failures with require.NoError, and adding focused coverage for GetCacheDir and additional sanitizePath normalization cases.

Changes:

  • Reworked TestImportCache subtests so each one builds its own cache instance instead of sharing mutable state.
  • Added explicit error assertions for Set(...) calls that previously ignored setup failures.
  • Added a dedicated TestGetCacheDir and two extra TestSanitizePath cases covering filepath.Clean normalization behavior.
Show a summary per file
File Description
pkg/parser/import_cache_test.go Tightens import cache unit-test isolation, adds direct GetCacheDir coverage, and extends sanitizePath test cases.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 1/1 changed files
  • Comments generated: 1

Comment thread pkg/parser/import_cache_test.go Outdated
Comment on lines +75 to +80
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
baseDir := tt.baseDir(t)
cache := NewImportCache(baseDir)
expected := filepath.Join(baseDir, ImportCacheDir)
assert.Equal(t, expected, cache.GetCacheDir(), "GetCacheDir should return base dir joined with ImportCacheDir")
@pelikhan
Copy link
Copy Markdown
Collaborator

pelikhan commented May 5, 2026

@copilot review all comments

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 5, 2026

@copilot review all comments

Addressed in 528a8c2: removed TestGetCacheDir and folded the nested-base-dir case as a t.Run subtest inside TestImportCacheDirectory, eliminating the duplicate GetCacheDir assertion.

Copilot AI requested a review from pelikhan May 5, 2026 00:42
@pelikhan pelikhan merged commit 873ce83 into main May 5, 2026
@pelikhan pelikhan deleted the copilot/testify-expert-improve-test-quality-another-one branch May 5, 2026 01:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[testify-expert] Improve Test Quality: pkg/parser/import_cache_test.go

4 participants